#define _CRT_SECURE_NO_WARNINGS 1
#include <string>
#include <iostream>
using namespace std;
//string test01()
//{
//    string str;
//    str.reserve(max(num1.size(), num2.size()) + 1);
//    int n1 = num1.size() - 1;
//    int n2 = num2.size() - 1;
//    int carry = 0;
//    while (n1 >= 0 || n2 >= 0)
//    {
//        int val1 = n1 >= 0 ? num1[n1--] - '0' : 0;
//        int val2 = n2 >= 0 ? num2[n2--] - '0' : 0;
//        int val = val1 + val2 + carry;
//        carry = val / 10;
//        val %= 10;
//
//        str += val + '0';
//    }
//    if (carry == 1)
//    {
//        str += '1';
//    }
//    reverse(str.begin(), str.end());
//    return str;
//}

void test02()
{
    //string::iterator it = s.begin();
    //string::iterator tmp = it;
    //int num = 0;
    //while (it < s.end())
    //{
    //    num = it - tmp;
    //    if (num == 2k)
    //    {
    //        reverse(tmp, );
    //    }
    //    else if ()
    //}
    string str("good");
    const char* arr = str.c_str();
    cout << arr << endl;
}

void test03()
{
    void Swap(char& x, char& y)
    {
        char tmp = x;
        x = y;
        y = tmp;
    }

    void reserve(char* arr)
    {
        int n1 = 0;
        int n2 = sizeof(arr) / sizeof(arr[0]);
        while (n1 < n2)
        {
            Swap(arr[n1], arr[n2]);
            n1++;
            n2--;
        }
    }

    class Solution {
    public:
        string reverseStr(string s, int k) {
            const char* arr = s.c_str();
            int first = 0;
            int last = 0;
            while (last < s.size())
            {
                if (last == 2 * k)
                {
                    reverse(&arr[first], &arr[first + k]);
                    first = last + 1;
                    last = first;
                }
                last++;
            }
            int rest = last - first;
            if (rest > k)
            {
                reverse(&arr[first], &arr[first + k]);
            }
            else
            {
                reverse(&arr[first], &arr[last]);
            }
        }
}
int main()
{
	//test01();
    //test02();
    test03();
	return 0;
}